<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%String path = request.getContextPath() ;%>
<%@ taglib uri="/WEB-INF/tld/c.tld" prefix="c" %>
<%@ taglib uri="/WEB-INF/tld/ui.tld" prefix="ui" %>
<!DOCTYPE html>
<html lang="zh-CN" >
<head>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>厂商贴息报价器</title>
<jsp:include page="../../import.jsp" flush="true" />
</head>
<body class="iframeBody">
<div class="Wrapper">
	<div id="pageInTab" class="pageInTab">
			<div tabid="tabA" title="基本信息" lselected="true">
	            <form id="formSet1">
	                <div class="fieldset1 tabel_col clearFix">
	                    <div class="fieldBox col_33">
		                    <div class="label">方案名称</div>
		                    <div class="field">
		                   <input name="prpsCfgNm" id="prpsCfgNm" type="text" class="ui-textbox"    value="${quatPrps.prpsCfgNm}" >
		                   <input name="prpsCfgId" id="prpsCfgId" type="hidden" class="ui-textbox"   value="${quatPrps.id}" >
		                   <input name="isDef" id="isDef" type="hidden" class="ui-textbox"   value="${quatPrps.isSysDef}" >
		            	   <input name="prpsId" id="prpsId" type="hidden" class="ui-textbox"   value="${id}" >
		            	   <input name="isAllowChg" id="isAllowChg" type="hidden" class="ui-textbox"   value="${quatPrps.isAllowChg}" >
		            	   <input name="isAllowAdd" id="isAllowAdd" type="hidden" class="ui-textbox"   value="${quatPrps.isAllowAdd}" >

		                    </div>
		                </div>

                        <div class="fieldBox col_33">
                            <div class="label">租赁物件总价值</div>
                            <div class="field">
                                <input name="totLsItmAmt" id="totLsItmAmt"  readonly="readonly" type="text" class="ui-textbox"   value="" validate="{required:true}">
                            </div>
                        </div>

		                 <div class="fieldBox col_33">
		                    <div class="label">合同总额（元）</div>
		                    <div class="field">
		                        <input name="contAmt" id="contAmt" type="text" class="ui-textbox"  value=""  onblur="changeBaseContAmt()" validate="{required:true}">
		                    </div>
		                </div>
		                 <div class="fieldBox col_100">
		                    <div class="label">租赁期数</div>
		                    <div class="field">
		                        <input name="lsPd" id="lsPd" type="number" class="ui-textbox"  value="${quatPrps.lsPd}"  onblur="searchAnnIntRatePct()" validate="{required:true,number:true}">
		                         <select name="lsPdUntCd" id="lsPdUntCd" data-value=" " onchange="searchAnnIntRatePct()">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${lsPdUntCdList }" var="kv">
									    <option value="${kv.key }"
									    <c:if test="${quatPrps.lsPdUntCd==kv.key}"> selected="selected"</c:if>
									    >${kv.value }</option>
									</c:forEach>
								</select>
								 </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">租赁周期</div>
		                    <div class="field">
		                      <span id="rentPeriod"></span>
		                    </div>
		                </div>
		                <div class="fieldBox col_33">
		                    <div class="label">租赁年利率%</div>
		                    <div class="field">
		                      <input name="annIntRatePct" id="annIntRatePct" type="text" class="ui-textbox"  value="">
		                    </div>
		                </div>
						<div class="fieldBox col_33">
							<div class="label">计算方式</div>
							<div class="field">
								<select name="lsCalWayCd" id="lsCalWayCd" data-value=" ">
									<c:forEach items="${lsCalWayCdList }" var="kv">
										<option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>

		                  <div class="fieldBox col_33">
		                    <div class="label">实际融资租赁价值</div>
		                    <div class="field">
		                       <input name="actLsAmt" id="actLsAmt" type="text" class="ui-textbox"  value=""  readonly="readonly">
		                    </div>
		                </div>
						<div class="fieldBox col_33">
							<div class="label">支付方式</div>
							<div class="field">
								<select name="payWayCd" id="payWayCd" data-value=" "  validate="{required:true}" onchange="speLsPdChange();">
									<option value=" " checked >请选择</option>
									<c:forEach items="${payWayCdList }" var="kv">
										<option value="${kv.key }"
												<c:if test="${quatPrps.payWayCd==kv.key}"> selected="selected"</c:if>
										>${kv.value }</option>
									</c:forEach>
								</select>
							</div>
						</div>
						<div class="fieldBox col_33" id = "speLsPdDiv" style = "display: none">
							<div class="label">不还款期数</div>
							<div class="field">
								<input name="speLsPd" id="speLsPd"  type="text" class="ui-textbox"  value="">
							</div>
						</div>
		                  <div class="fieldBox col_33">
		                    <div class="label">每期预估租金</div>
		                    <div class="field">
		                      <input name="eachEstRntAmt" id="eachEstRntAmt"  type="text" class="ui-textbox"  value="" readonly="readonly">
		                    </div>
		                </div>
		               <div class="fieldBox col_33">
		                    <div class="label">租赁年利率计算方式</div>
		                    <div class="field">
		                        <select name="intRateWayCd" id="intRateWayCd" data-value=" ">
		                        	<option value=" " checked >请选择</option>
									<c:forEach items="${intRateWayCdList }" var="kv">
									    <option value="${kv.key }" >${kv.value }</option>
									</c:forEach>
								</select>
		                    </div>
		                </div>
		                  <div class="fieldBox col_33">
		                    <div class="label">首付款</div>
		                    <div class="field">
		                    <span id="firstPayAmt"></span>
		                    </div>
		                </div>
		                   <div class="fieldBox col_33">
		                    <div class="label">实际收益率(IRR)</div>
		                    <div class="field">
		                      <input name="irrPct" id="irrPct"  type="text" class="ui-textbox"  value=""  readonly="readonly" validate="{number:true}">
		                    </div>
		                </div>

		                 <div class="fieldBox col_33"  id="prpsTypCdDiv" >
		                    <div class="label">产品方案政策类型</div>
		                    <div class="field">
		                    <select name="prpsTypCd" id="prpsTypCd" data-value=""  >
		                        	<option value="" checked>请选择</option>
									<c:forEach items="${mfrPrpsTypCdList}" var="kv">
									    <option value="${kv.key }">${kv.value}</option>
									</c:forEach>
							</select>
		                    </div>
		                </div>
                      <%--   <div class="fieldBox col_33"  id="prdIrrPctDiv" >
                             <div class="label">产品类型</div>
                             <div class="field">
                                 <select name="prdIrrPct" id="prdIrrPct" data-value=""  >
                                     <option value="" checked >请选择</option>
                                     <c:forEach items="${prdTypIrrList}" var="kv">
                                         <option value="${kv.code}" code="${kv.codeNm}">${kv.codeDesc}</option>
                                     </c:forEach>
                                 </select>
                             </div>
                         </div>--%>

						<div class="fieldBox col_33"  id="insQuatTypDiv" style="display:none"  >
							<div class="label">模式</div>
							<div class="field">
								<select name="insQuatTyp" id="insQuatTyp" data-value=""  onchange="getChange()">
									<option value="" checked >请选择</option>
									<c:forEach items="${insQuatTypList}" var="kv">
										<option value="${kv.key}">${kv.value}</option>
									</c:forEach>
								</select>
							</div>
						</div>

					 <div class="fieldBox col_100"  id="insCodeDiv" style="display:none">
                            <div class="label">支持资管机构</div>
                            <div class="field" id="insCode"></div>
                        </div>

                        <div class="fieldBox col_33"  id="prdIrrPctDiv" >
                            <div class="label">产品IRR</div>
                            <div class="field">
                                <input name="prdIrrPct" id="prdIrrPct"  type="text" class="ui-textbox"  value=""  validate="{number:true}">
                            </div>
                        </div>
		                <div class="fieldBox col_33"  id="irrPct2Div" >
		                    <div class="label">实际收益率(IRR2)</div>
		                    <div class="field">
		                      <input name="irrPct2" id="irrPct2"  type="text" class="ui-textbox"  value=""   readonly="readonly" validate="{number:true}">
		                    </div>
		                </div>
                        <div class="fieldBox col_33">
                            <div class="label">租赁年利率2%</div>
                            <div class="field">
                                <input name="annIntRatePct2" id="annIntRatePct2" type="text" class="ui-textbox" readonly="readonly" value="">
                            </div>
                        </div>
                        <%--<div class="fieldBox col_100"  id="msgDiv" style="display: none">
                            <div class="label">支持的资管机构：</div>
                            <div class="field">
                                <span style="color: red" id="checkInfo"></span>
                            </div>
                        </div>--%>
				        <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div class="sqPanel_head inL">
				                    <div class="btnsBox inLC">
				                        <span id="addBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_3"></i> -->添加</span>
				                        <span id="delBtn" class="sq-button sq-button-round"><!-- <i class="sqBtnIco_7"></i> -->删除</span>
				                    </div>
				                </div>
				                 <br/>
				                  <br/>
				                <div id="detailGrid">
				                    <div id="ligergrid_fee" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				          <div class="fieldBox col_100">
				            <div class="sqPanel">
				                <div id="feePayGrid">
				                    <div id="ligergrid_calculate" class="sq-grid"></div>
				                </div>
				            </div>
				        </div>
				         <div class="fieldBox col_33">
		                    <div class="label">合计租金：</div>
		                    <div class="field">
		                    <span id="totalRntAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计本金：</div>
		                    <div class="field">
		                    <span id="totalPrinAmt"></span>
		                    </div>
		                </div>
		                 <div class="fieldBox col_33">
		                    <div class="label">合计利息：</div>
		                    <div class="field">
		                    <span id="totalIntAmt"></span>
		                    </div>
		                </div>
	                </div>
	                <div class="btnsBox">
	                   <span id="calculateBtn1"  class="sq-button sq-button-round">测算</span>
		                <span id="saveBtn1" class="sq-button sq-button-round">保存</span>
		            </div>
	            </form>
		</div>
	</div>
</div>

<script type="text/javascript">
var feeGrid;//费用明细信息
var quatId = '${quatId}';
var detailFlag = '${detailFlag}';
var calculateGrid;
var annIntRatePct = 0;
var isModify = false;
var prpsCfgId = '${prpsCfgId}';
var quatPrps='${quatPrps}';
var quatPrpsJson  ='${quatPrpsJson}';
var prpsTypCd = '${prpsTypCd}';
//事业部
var buOrgCd = '${buOrgCd}';

//费用类型
var feeTypCdListJSON = [];
<c:if test="${not empty feeTypCdListJSON}"> feeTypCdListJSON = ${feeTypCdListJSON}; </c:if>
//费用计算基数
var calBaseCdListJSON = [];
<c:if test="${not empty calBaseCdListJSON}"> calBaseCdListJSON = ${calBaseCdListJSON}; </c:if>
//费用计入方式
var cntWayCdListJSON = [];
<c:if test="${not empty cntWayCdListJSON}"> cntWayCdListJSON = ${cntWayCdListJSON}; </c:if>
//是否
var yesOrNoCdListJSON = [];
<c:if test="${not empty yesOrNoCdListJSON}"> yesOrNoCdListJSON = ${yesOrNoCdListJSON}; </c:if>
var scaleNumMap = '${scaleNumMap}';
var feeScale = 0;
var annIntScale = 0;
var floatScale = 0;
if(scaleNumMap.length>0){
	scaleNumMap = JSON.parse(scaleNumMap);
for(var key in scaleNumMap) {
	if(key==ProjectConstant.CODE_ANNINT_RATE_NUM_CD){
	annIntScale = parseInt(scaleNumMap[key]);
	}
	if(key==ProjectConstant.CODE_FLOAT_RATE_NUM_CD){
	floatScale = parseInt(scaleNumMap[key]);
	}
	if(key==ProjectConstant.CODE_FEE_DECI_NUM_CD){
	feeScale = parseInt(scaleNumMap[key]);
	}
}
} else{
	feeScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
	annIntScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
	floatScale = ProjectConstant.CODE_DEF_FEE_DECI_NUM;
}



/**
 * 当模式模块有值的时候，机构模块才会显示出来
 */
function getChange() {

    var he = ${requestScope.diffInsCodeAndinsQuatTyp};

    var insQuatTypVal = $("#insQuatTyp").val();

    if ( insQuatTypVal != null  && insQuatTypVal != "") {

        $("#insCodeDiv").show();

        //显示的机构
        var showInsCode = "";
        for(var i=0;i < he.length; i++){
            var obj = he[i];

            if (insQuatTypVal == obj.insQuatTyp) {
                showInsCode += obj.insCode + ",";
            }
        }
        document.getElementById("insCode").innerText=showInsCode.substring(0, showInsCode.length - 1)

    } else {
        $("#insCodeDiv").hide();
    }
}




$(function(){
	$('#formSet1').ligerForm({
        validate : true
	});
	var editFlag = true;
 	if(detailFlag=="true"){
		editFlag = false;
		$("#calculateBtn1").hide();
		$("#saveBtn1").hide();
		$("#addBtn").hide();
		$("#delBtn").hide();
	}
	var prpsId=$("#prpsId").val();
	if(!prpsId){
		 var baseForm1 = liger.get("formSet1");
		 baseForm1.setData({
			 intRateWayCd:ProjectConstant.CODE_DEF_INT_RATE_WAY_CD
     	 });
	}

	if(prpsId){
	var prjQuatPrps = '${prjQuatPrps}';
	 prjQuatPrps = JSON.parse(prjQuatPrps);
		//初始化修改数据
	 	 var form = liger.get("formSet1");
	 		form.setData({
	 			prpsCfgNm:prjQuatPrps.prpsCfgNm,
	 			prpsCfgId:prjQuatPrps.prpsCfgId,
	 			isSysDef:prjQuatPrps.isSysDef,
	 			prpsId:prjQuatPrps.prpsId,
	 			totLsItmAmt:prjQuatPrps.totLsItmAmt,
	 			contAmt:prjQuatPrps.contAmt,
	 			intRateRsPct:parseFloat(prjQuatPrps.intRateRsPct==null?0:prjQuatPrps.intRateRsPct),
	 			lsPd:prjQuatPrps.lsPd,
	 			lsPdUntCd:prjQuatPrps.lsPdUntCd,
	 			annIntRatePct:parseFloat(prjQuatPrps.annIntRatePct==null?0:prjQuatPrps.annIntRatePct),
                annIntRatePct2:parseFloat(prjQuatPrps.annIntRatePct2==null?0:prjQuatPrps.annIntRatePct2),
	 			payWayCd:prjQuatPrps.payWayCd,
				speLsPd:prjQuatPrps.speLsPd,
	 			actLsAmt:prjQuatPrps.actLsAmt,
	 			eachEstRntAmt:prjQuatPrps.eachEstRntAmt,
	 			lsCalWayCd:prjQuatPrps.lsCalWayCd,
	 			intRateWayCd:prjQuatPrps.intRateWayCd,
	 			irrPct:prjQuatPrps.irrPct,
	 			irrPct2:prjQuatPrps.irrPct2,
                prdIrrPct:prjQuatPrps.prdIrrPct,
                prpsTypCd:prjQuatPrps.prpsTypCd,

                //初始化修改的数据
				// insCode:prjQuatPrps.insCode,
                insQuatTyp:prjQuatPrps.insQuatTyp
	 		 });

		if(prjQuatPrps.payWayCd==ProjectConstant.CODE_MULTI_STEP_INTER_19){
			$("#speLsPdDiv").show();
		}else{
			$("#speLsPdDiv").hide();
		}
			if ($("#prpsTypCd").val() == "ZGCP") {
				$("#insQuatTypDiv").show();

                if ($("#insQuatTyp").val() != null  && $("#insQuatTyp").val() != "") {
                    $("#insCodeDiv").show();
                } else {
                    $("#insCodeDiv").hide();
                }

			} else {
				$("#insQuatTypDiv").hide();
                $("#insCodeDiv").hide();
			}


            modifyData(prjQuatPrps);


	 		$("#prpsCfgId").val(prjQuatPrps.prpsCfgId);
	 		$("#isAllowChg").val(prjQuatPrps.isAllowChg);
	 		$("#isAllowAdd").val(prjQuatPrps.isAllowAdd);

	 		$("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
	 		$("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
			$("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
			$("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
			annIntRatePct = prjQuatPrps.annIntRatePct;
	 		setRentPeriod();
	 		var isAllowAdd = $("#isAllowAdd").val();
	 		if(isAllowAdd&&isAllowAdd==CommonConstant.C_YN_N){
	 			$("#addBtn").hide();
	 			$("#delBtn").hide();
	 		}
		//初始化费用明细
	  var url = '<%=path%>/project/calquatprps/getCalQuatFeeById.do?id='+prpsId;
		prjQuatPrpsfeeGrid(url,editFlag);
		//初始化支付表明细
			var flag = false;
			initCalculatePage(flag);
	}else{
		var prpsCfgId = $("#prpsCfgId").val();
		var url= '<%=path%>/project/prjQuatPrpsCfgD/initList.do?prpsCfgId='+prpsCfgId;
		prjQuatPrpsfeeGrid(url,editFlag);
	}


	//isAllowChg 设置form字段是否可以修改
	//是否允许变更（5位标识位，1：租赁期数，2：支付方式，3：保证金处理方式，4：租赁期满处理方式，5：租赁年利率）
	var isAllowChg = $("#isAllowChg").val();
	if(isAllowChg){
	  var isAllowChgStr= new Array();
	  isAllowChgStr=isAllowChg.split(";");//字符分割
		for (i=0;i<isAllowChgStr.length ;i++ )
		{
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_LS_PD){
				//租赁期数
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					$("#lsPd").attr("readonly","readonly");
					  liger.get("lsPdUntCd").setDisabled(true);
				}
			}
			if(i+1==ProjectConstant.CODE_PRJ_QUAT_PAY_WAY){
				//支付方式
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					  liger.get("payWayCd").setDisabled(true);
					}
			}

			if(i+1==ProjectConstant.CODE_PRJ_QUAT_ANNINT_RATE_PCT){
				//租赁年利率
				if(isAllowChgStr[i]==CommonConstant.C_YN_N){
					$("#annIntRatePct").attr("readonly","readonly");
				}
			}
		}

	}

 	 $('#annIntRatePct').toFixNumber(annIntScale,
	            {
	                onToFix: function () {
	                    $.ligerDialog.SQalert({SQ_type: "warning", content: "小数点后不要超过"+annIntScale+"位数！"});
	                }
	        }
	 );

	$("#calculateBtn1").click(function(event) {
		var flag = false;
		initCalculateGrid(flag);
	 });

	$("#saveBtn1").click(function(event) {
	    var form = liger.get("formSet1");
	    if (!form.valid()) {
	    	$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO , SQ_type: "warning" });
            return false; //验证不通过，不执行以下代码
        }
        addPrjQuatPrps();
});

	function addPrjQuatPrps(){
		    var form = liger.get("formSet1");
		    if (!form.valid()) {
	            top.$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_MUST_FIX_ITEM_INFO,SQ_type: "warning"});
	            return false; //验证不通过，不执行以下代码
	        }
		  var data = form.getData();
		  var payTypCd = $("#payWayCd").val();
		  var lsPd = $("#lsPd").val();
							   var detailListData = feeGrid.getData();
							    var calculateData;
							    if(calculateGrid){
							     calculateData = calculateGrid.getData();
							    }
							    var id = $("#prpsId").val();
					         data["id"]= id;
					         data["lsPdUntCd"]=$("#lsPdUntCd").val();
					         data["payWayCd"]=$("#payWayCd").val();
					         data["lsCalWayCd"]=$("#lsCalWayCd").val();
					         data["intRateWayCd"]=$("#intRateWayCd").val();
					         data["prpsCfgId"]=$("#prpsCfgId").val();
					         data["prpsCfgNm"]=$("#prpsCfgNm").val();
					         data["isAllowChg"]=$("#isAllowChg").val();
					         data["isAllowAdd"]=$("#isAllowAdd").val();
					         data["prpsCfgId"]=$("#prpsCfgId").val();
                            data["prpsTypCd"]=$("#prpsTypCd").val();
                            data["actLsAmt"]=$("#actLsAmt").val();

                            //资管机构的选中的银行及模式
							data["insCode"]=$("#insCode").val();
							data["insQuatTyp"]=$("#insQuatTyp").val();

                           // var prdIrrPct = liger.get("prdIrrPct").select.find('[selected="selected"]').attr("code");
                            data["prdIrrPct"] = $("#prdIrrPct").val();
                           // data["prdTypCd"] = $("#prdIrrPct").val();
					     	 data["feeDetailList"] = JSON.stringify(detailListData);
					  	 data["payList"] = JSON.stringify(calculateData);
					  var url = '<%=path%>/project/calquatprps/addQuatPrps.do';
					  var wait_dialog;
					  $.ajax({
							type: 'post',
							dataType:'json',
							data:data,
							url: url,
							beforeSend: function(){
						          wait_dialog=$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_DATA_LOADING ,SQ_type: "waitting" });
						     },
                                success:function(msg){
								 wait_dialog.close();
								 if(msg.success == 1){
									 $.ligerDialog.SQalert({content:msg.info, SQ_type: "success"});
									 if(msg.data){
										 $("#prpsId").val(msg.data);
										 top.$.ligerDialog.SQalert({content: "保存成功！",SQ_type: "success"});
										 var TAB=top.mainApp.parentTab;
					  			            var currentTabid=TAB.getSelectedTabItemID();
					  			             var currFrameElement=top.$("#"+currentTabid).get(0);
					  						 var callback=currFrameElement.W2W.callback;
								          	  		callback();
								          	 	 top.tab.removeTabItem(currentTabid);

									 }
								 }else{
									 $.ligerDialog.SQalert({content:msg.info, SQ_type: "error"});
								 }
							}
						});



		  }

	$("#addBtn").click(function (event) {
        feeGrid.addRow({
        	feeTypCd: '',
        	calBaseCd: '',
        	feePct: 0,
        	feeAmt:0,
        	cntWayCd: '',
        });
    });
	$("#delBtn").click(function (event) {
        var selectedRows = feeGrid.getSelectedRows();
        if(selectedRows.length != 1){
			$.ligerDialog.SQalert({content: LogUtils.LOG_CMM_SELECT_ONLY_A_ROW, SQ_type: "warring"});
			return;
		}
		for ( var index in selectedRows) {
			if(selectedRows[index].isSysDef){
				if(selectedRows[index].isSysDef==CommonConstant.C_YN_Y){
					$.ligerDialog.SQalert({content: "不允许删除方案配置费用项", SQ_type: "warring"});
					return;
				}
			}
		}
        feeGrid.deleteSelectedRow();
    });
	if(detailFlag=="true"){
	if($("#prpsCfgNm")){
		$("#prpsCfgNm").attr("readonly","readonly");
	}
	if($("#totLsItmAmt")){
		$("#totLsItmAmt").attr("readonly","readonly");
	}
	if($("#contAmt")){
		$("#contAmt").attr("readonly","readonly");
	}
	if($("#lsPd")){
		$("#lsPd").attr("readonly","readonly");
	}
	if($("#annIntRatePct")){
		$("#annIntRatePct").attr("readonly","readonly");
	}
	if($("#actLsAmt")){
		$("#actLsAmt").attr("readonly","readonly");
	}
	if($("#eachEstRntAmt")){
		$("#eachEstRntAmt").attr("readonly","readonly");
	}
	if($("#lsCoe")){
		$("#lsCoe").attr("readonly","readonly");
	}
	if($("#intRateRsPct")){
		$("#intRateRsPct").attr("readonly","readonly");
	}
    if($("#prdIrrPct")){
        $("#prdIrrPct").attr("readonly","readonly");
    }


	if(liger.get("lsPdUntCd")){
		  liger.get("lsPdUntCd").setDisabled(true);
	}
	if(liger.get("payWayCd")){
		  liger.get("payWayCd").setDisabled(true);
	}
	if(liger.get("lsCalWayCd")){
		  liger.get("lsCalWayCd").setDisabled(true);
	}
	if(liger.get("intRateWayCd")){
		  liger.get("intRateWayCd").setDisabled(true);
	}

	}
	//如果配置方案不可添加，隐藏费用添加、删除按钮]
	var isAllowAdd = $("#isAllowAdd").val();
	if(isAllowAdd==CommonConstant.C_YN_N){
		$("#addBtn").hide();
		$("#delBtn").hide();
	}


	/**
     * 当产品方案政策类型的值等于资管产品的时候，
     * 模式div就会显示出来，否则不显示,
     * 当产品方案类型不是资管产品的时候，模式和机构都不显示出来
     * 当产品方案类型选择其他类型时，将模式选中的文本清除掉
     */
    $("#prpsTypCd").change(function () {
        var prpsTypCdVal = $("#prpsTypCd").val();
        if (prpsTypCdVal == "ZGCP") {
            $("#insQuatTypDiv").show();

        } else {
            var selectid= $("#insQuatTyp").ligerGetComboBoxManager();
            $("#insQuatTyp").val("");
            selectid.setValue($("#insQuatTyp").val());
            selectid.setText($("#insQuatTyp").find(":selected").text());

            $("#insQuatTypDiv").hide();
            $("#insCodeDiv").hide();
        }
    });

});


/**
 * 初始化支持资管机构
 * @param obj
 */
function modifyData (obj) {

    var he =  ${requestScope.diffInsCodeAndinsQuatTyp};
    var insQuatTypVal = obj.insQuatTyp;

    if (insQuatTypVal != null  && insQuatTypVal != "") {

        var s1 = "";
        for(var i=0;i < he.length; i++){
            var obj = he[i];
            // alert("出现的模式："+ obj.insQuatTyp)
            if (insQuatTypVal == obj.insQuatTyp) {

                s1 += obj.insCode + ",";
            }
        }
        document.getElementById("insCode").innerText=s1.substring(0, s1.length - 1)
    }
}

function deleteRow(){
	var manager = $("#ligergrid_fee").ligerGetGridManager();
	 manager.deleteSelectedRow();
}

function prjQuatPrpsfeeGrid(url,editFlag){
	feeGrid = $("#ligergrid_fee").ligerGrid({
		url:url,
        method: 'get',
        columns: [
            {display: '费用类型', name: 'feeTypCd', minWidth: 80,
                editor: {
                    type: 'select',
                    data: feeTypCdListJSON,
                    valueField: 'code',
                    textField: 'codeNm'
                },
                valueField: 'feeTypCd',
                textField: 'feeTypCdNm',
                render: function (item) {
                    return item.feeTypCdNm;
                }
            },
            {display: '是否为固定值', name: 'isFixedAmt', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: yesOrNoCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'isFixedAmt',
                textField: 'isFixedAmtNm',
                render: function (item) {
                    return item.isFixedAmtNm;
                }
            },
            {display: '计算基数', name: 'calBaseCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: calBaseCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'calBaseCd',
                textField: 'calBaseCdNm',
                render: function (item) {
                    return item.calBaseCdNm;
                }
            },

            {display: '比例值（%）', name: 'feePct', minWidth: 80, type: 'numberbox',

            	editor: {type: 'number',
            				precision:feeScale,
            				toFix:true,
            				onToFix:function(){
            					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多"+feeScale+"小数！"});
            				}
            		},
            render: function (item) {
            	if(item.isFixedAmt!=1){
            		item.feePct = Number(item.feePct);
	            	if(typeof item.feePct =='number'){
                        var pct =  (parseFloat(item.feePct)).toFixed(2)
                        return pct;
	            	}
            	}else{
            		return 0;
            	}
            }

            },
            {display: '金额（元）', name: 'feeAmt', minWidth: 80, render:renderAmt,type: 'numberbox',
            	editor: {type: 'number',
		            		precision:2,
		    				toFix:true,
		    				onToFix:function(){
           					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
           				}
            	}

            },

            {display: '计入方式', name: 'cntWayCd', minWidth: 80,
            	editor: {
                    type: 'select',
                    data: cntWayCdListJSON,
                    valueField: 'key',
                    textField: 'value'
                },
                valueField: 'cntWayCd',
                textField: 'cntWayCdNm',
                render: function (item) {
                    return item.cntWayCdNm;
                }
            }

        ],
       onLoaded:function(){
    	   var quatPrps = '${id}';
    	   if(!quatPrps){
        	//changeBaseTotLsltmAmt();
        	changeBaseContAmt();
    	   }
        	this.toggleLoading(false);
        },
        onBeforeEdit: function(e){
        	var colNanme = e.column.columnname;
	        	if(e.record.isAllowChg==0){
                  	   e.column.editor.readonly = true;
        		}else{
        			e.column.editor.readonly = false;
        			if(e.record.isSysDef==1){
           		 	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
                       if (colNanme == "cntWayCd" || colNanme == "calBaseCd"|| colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
                    	   e.column.editor.readonly = true;
                       }
                       if(e.record.isFixedAmt==1){
                    	   if (colNanme == "feePct") {
                        	   e.column.editor.readonly = true;
                           }
           		 	 }else{
           		 	 if (colNanme == "feePct") {
                  	   e.column.editor.readonly = false;
                     }
           		 	 }
           			}else{
           		      if (colNanme == "cntWayCd" || colNanme == "isFixedAmt"||colNanme == "feeTypCd") {
                   	   e.column.editor.readonly = false;
                      }
           			 if(e.record.isFixedAmt==1){
               		 	 //根据行数据里的"editable"属性，指定是否可以编辑这一行数据
                           if (colNanme == "feePct" || colNanme == "calBaseCd") {
                               if (e.record.editable == 1) {
                                   e.column.editor.readonly = true;
                               }else{
                                   e.column.editor.readonly = false;
                               };
                           }
           			}else{
           		      if (colNanme == "feePct" || colNanme == "calBaseCd") {
                              e.column.editor.readonly = false;
                      }

           			}

        		}
        		}

            //事业部新车业务供应商返利和销售返利不可编辑
            saleAndSupplierRebate(e);

        },
        onAfterEdit: function (e) {
          var calBaseCd = e.record.calBaseCd;
          var isFixedAmt = e.record.isFixedAmt;
          var  feeTypCd = e.record.feeTypCd;
        	if(e.column.name =="feePct"){
        		var pct = e.record.feePct;
          		 var minPct = e.record.feePctMin;
            	 var maxPct = e.record.feePctMax;
            	 if(pct&&minPct&&maxPct&&pct!="undefined"&&minPct!="undefined"&&maxPct!="undefined"){
	             	 if(pct<minPct||pct>maxPct){
	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "请输入"+minPct+"~"+maxPct+"之间的数值！"});
	             		  e.value = e.lastValue;
	             		 feeGrid.updateRow(e.record,{
	              			feePct: e.value
	                      });
	             	 }else{
	             		 pct = Number(pct);
	            		 if(typeof pct =='number'&&isFixedAmt!=1){
	            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
	 		             	 feeGrid.updateCell('feePct', e.value, e.record);
	 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
	 		              }
	             	 }
            	 }else{
            		 if(minPct==0||minPct==0){
            	      	 if(pct<minPct||pct>maxPct){
   	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "请输入"+minPct+"~"+maxPct+"之间的数值！"});
   	             		  e.value = e.lastValue;
   	             		 feeGrid.updateRow(e.record,{
   	              			feePct: e.value
   	                      });
   	             	 }else{
   	             	 pct = Number(pct);
            		 if(typeof pct =='number'&&isFixedAmt!=1){
            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
 		             	 feeGrid.updateCell('feePct', e.value, e.record);
 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
 		             	 }
   	             	 }
              }else{
            		 pct = Number(pct);
            		 if(typeof pct =='number'&&isFixedAmt!=1){
            			  var amt = getAmt(e.value,calBaseCd,feeTypCd,isFixedAmt);
 		             	 feeGrid.updateCell('feePct', e.value, e.record);
 		             	 feeGrid.updateCell('feeAmt', amt, e.record);
 		             	 }
            		 }

                 }

            	 
        	}

       	//如果为固定金额，设置比例字段为只读
    	if(e.column.name =="isFixedAmt"){
   		 var isFixedAmt = e.record.isFixedAmt;
   		 var calBaseCd = e.record.calBaseCd;
   		 if(isFixedAmt==CommonConstant.C_YN_Y){
   		 	e.record.calBaseCd=' ';
   			e.record.calBaseCdNm = ' ';
   			e.record.feePct='  ';
             feeGrid.updateCell('feePct', '', e.record);
             feeGrid.updateCell('feeAmt', 0, e.record);
             feeGrid.updateCell('calBaseCd', ' ', e.record);
   		 }

   	}
         	if(e.column.name =="calBaseCd"){
        		 var feeTypCd = e.record.feeTypCd;
        		 var calBaseCd = e.record.calBaseCd;
        		 var isFixedAmt = e.record.isFixedAmt;
        		if(feeTypCd=="01"&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
        			//首期款
        			top.$.ligerDialog.SQalert({SQ_type: "warning",content: "首期款的计算基数不能为融资额！"});
        		}
        		 var feeAmt = e.record.calBaseCd;
        		 var feePct = e.record.feePct;
        	      var  feeTypCd = e.record.feeTypCd;
				if(feePct){
					if(feePct>0){
						  var amt = getAmt(feePct,calBaseCd,feeTypCd,isFixedAmt);
			             	 feeGrid.updateCell('feeAmt', amt, e.record);
					}

				}

        	}
         	if(e.column.name =="feeAmt"){
        		var feeAmt = e.value;
         		 var minPct = e.record.feePctMin;
           		 var maxPct = e.record.feePctMax;
            	 var isFixedAmt = e.record.isFixedAmt;
                 var  feeTypCd = e.record.feeTypCd;
            	 var feePct = getPct(feeAmt,calBaseCd,feeTypCd,isFixedAmt);
            	 var maxPct = e.feePctMax;
            	 if(feePct&&minPct&&maxPct&&feePct!="undefined"&&minPct!="undefined"&&maxPct!="undefined"){
	             	 if(feePct<minPct||feePct>maxPct){
	             		  top.$.ligerDialog.SQalert({SQ_type: "warning",content: "比例不在规定的范围内，范围：["+minPct+"~"+maxPct+"]请调整！"});
	             		 e.value = e.lastValue;
	             		 feeGrid.updateRow(e.record,{
	             			feeAmt: e.value
	                      });
	             	 }
             	 }else{
             		 if(typeof feeAmt =='number'&&isFixedAmt!=1){
             		feeGrid.updateCell('feePct', feePct, e.record);
             		 }
             	 }
       	}
        },
        onBeforeSubmitEdit: function (e) {//重新赋值,要不然选中后离开会把key显示在前端
            if (e.selected && e.column.columnname == "feeTypCdNm") {
                e.record.feeTypCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "calBaseCdNm") {
                e.record.calBaseCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "cntWayCdNm") {
                e.record.cntWayCdId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if (e.selected && e.column.columnname == "isFixedAmtNm") {
                e.record.isFixedAmtId = e.value;
                e.value = e.selected[e.column.editor.textField];
            }
            if(e.column.columnname == "isFixedAmt" && e.selected) e.record.editable = e.selected.key;
        },
        usePager: false,
        root: 'rows',
        record: 'total',
        hideLoadButton: true,
        width: '100%',
        height: 300,
        heightDiff: -2,
        enabledEdit: editFlag,
        isScroll: false,
        checkbox: editFlag,
        rownumbers: true,
        allowUnSelectRow: true,
        alternatingRow: false,
        enabledSort: false
    });
	}



/**
 * 事业部新车业务供应商返利和销售返利不可编辑
 */
function saleAndSupplierRebate(e) {

    if (buOrgCd == ProjectConstant.CODE_BU_ORG_CD_ZK ) {
        //供应商返利
        if(e.record.feeTypCd== ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_08 && e.record.feeTypCdNm == '供应商返利'){
            e.column.editor.readonly = true;
        }
        //销售返利
        if(e.record.feeTypCd==ProjectConstant.CODE_PRJ_QUAT_FEE_TYPE_49 && e.record.feeTypCdNm == '销售返利'){
            e.column.editor.readonly = true;
        }
    }
}

function initCalculateGrid(flag){
    var form = liger.get("formSet1");
	var data = form.getData();
	var payTypCd = $("#payWayCd").val();
    var lsPd = $("#lsPd").val();
		   var detailListData = feeGrid.getData();
		    var id = $("#prpsId").val();
	           data["id"]= id;
	           data["lsPdUntCd"]=$("#lsPdUntCd").val();
	           data["payWayCd"]=$("#payWayCd").val();
	           data["lsCalWayCd"]=$("#lsCalWayCd").val();
	           data["intRateWayCd"]=$("#intRateWayCd").val();
	           data["prpsCfgId"]=$("#prpsCfgId").val();
	       	   data["feeDetailList"] = JSON.stringify(detailListData);
	       	   data["isModify"] = isModify;
	       	   data["prpsTypCd"]=$("#prpsTypCd").val();
	       	   data["actLsAmt"]=$("#actLsAmt").val();
              // var prdIrrPct = liger.get("prdIrrPct").select.find('[selected="selected"]').attr("code");
               data["prdIrrPct"] = $("#prdIrrPct").val();
               //资管机构
	           data["insCode"]=$("#insCode").val();
	           data["insQuatTyp"]=$("#insQuatTyp").val();

               //data["prdTypCd"] = $("#prdIrrPct").val();
	       	var payWay = $("#payWayCd").val();
	       	var calculateGridData ;
	$.ajax({
		type: 'post',
		dataType:'json',
		data:data,
		url: '<%=path%>/project/calquatprps/calculate.do',
		success:function(msg){
			 if(msg.success == 1){
				 prjQuatPrps = msg.data;
				 calculateData =  msg.data.payListPage;
				 $("#totalRntAmt").text(prjQuatPrps.totalRntAmt);
				 $("#totalPrinAmt").text(prjQuatPrps.totalPrinAmt);
				 $("#totalIntAmt").text(prjQuatPrps.totalIntAmt);
				 $("#firstPayAmt").text(prjQuatPrps.firstPayAmt);
				 $("#actLsAmt").val(prjQuatPrps.actLsAmt);
				 $("#irrPct").val(prjQuatPrps.irrPct);
				 $("#irrPct2").val(null==prjQuatPrps.irrPct2?"":prjQuatPrps.irrPct2);
                 $("#annIntRatePct2").val(null==prjQuatPrps.annIntRatePct2?"":prjQuatPrps.annIntRatePct2);
				 $("#eachEstRntAmt").val(prjQuatPrps.eachEstRntAmt);
				 if(!prjQuatPrps.checkResultDesc&&prjQuatPrps.prpsTypCd=='ZGCP'){
                        $("#msgDiv").show();
                        $("#checkInfo").text("该方案无合适的机构！");
                 }
                 if(prjQuatPrps.checkResultDesc&&prjQuatPrps.prpsTypCd=='ZGCP'){
                     $("#msgDiv").show();
                     $("#checkInfo").text(prjQuatPrps.checkResultDesc);
                 }
                 if(prjQuatPrps.prpsTypCd=='ZGCP'){
                     $("#annIntRatePct").val(null==prjQuatPrps.annIntRatePct?"":prjQuatPrps.annIntRatePct);
                 }
				 calculateGrid = $("#ligergrid_calculate").ligerGrid({
				    	data: $.extend(true,{},calculateData),
				        columns: [
				            { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
				            { display: '期次', name: 'payPd',minWidth: 140},
				            { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,
				             	editor: {type: 'number',
				             		precision:2,
				    				toFix:true,
				    				onToFix:function(){
		           					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
		           				}},
				            	enabledSort:true},
				            { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
				            		render:renderAmt},
				            { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
				            			render:renderAmt},
				            { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
				            				render:renderAmt},
				        ],
				        onBeforeEdit: function (e) {
			                e.lastValue = e.value;
			                if(!e.record.isModify){
			                	e.record.isModify= CommonConstant.C_YN_N;
			                }
			            },
				        onAfterEdit: function (e) {
				            var calBaseCd = e.record.calBaseCd;
				          	if(e.column.name =="rntAmt"){
				          		var value = e.value;
				          	var lastValue = e.lastValue;
				               	 if(value!=lastValue&&lastValue){
				               		 isModify = true;
				               		e.record.isModify= CommonConstant.C_YN_Y;
				               	 }
				          	}

				          },
				        usePager: false,
				        pageSize:10,
				        root:'rows',
				        record:'total',
				        hideLoadButton : true,
				        width: '100%',
				        height:300,
				        heightDiff:-2,
				        //isScroll: false,
				        checkbox:true,
				        enabledEdit: flag,
				        rownumbers:true
				  });
			 }else{
				 top.$.ligerDialog.SQalert({content: msg.info,SQ_type: "error"});
			 }
		}
	});
}


function getPct(feeAmt,calBaseCd,feeTypCd,isFixedAmt){
	var feeFct = '';
	if(feeAmt&&isFixedAmt!=1){
	//计算费用值
	if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		var firstAmt =0;
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		  var rows = feeGrid.rows;
			 for (var i = 0; i < rows.length; i++) {
			  			var feeTypCd = rows[i].feeTypCd;
				 if(feeTypCd=="01"){
	        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
			  			var calCd = rows[i].calBaseCd;
			  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
			  			firstAmt  =(detailFct*contAmt).toFixed(2);
			  			}
			  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
			  				firstAmt  =(detailFct*totalAmt).toFixed(2);
			  			}
		  			}
			 }
			var financ = contAmt-firstAmt;
		feeFct =(parseFloat(feeAmt)/financ*100).toFixed(feeScale);
	}

	if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			//根据合同额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		feeFct =(parseFloat(feeAmt)/contAmt*100).toFixed(feeScale);
		}
	//设备款
	if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
		//根据合同额计算
	var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
	feeFct =(parseFloat(feeAmt)/totalAmt*100).toFixed(feeScale);
	}
	//如果更改首期款，融资额费用项为不可修改，按比例重新计算计入融资额的费用项，如果融资额费用项可以修改，清空费用项，修改实际融资额值
	if(feeTypCd=='01'){
		var firstAmt = 0;
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		 var detailFct = parseFloat(feeFct)/100;
			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			firstAmt  =(detailFct*contAmt).toFixed(2);
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				firstAmt  =(detailFct*totalAmt).toFixed(2);
			}
		//融资额
		var finaAmt = 0;
		if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			finaAmt  =contAmt-firstAmt;
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				finaAmt  =totalAmt-firstAmt;
			}
			//设置实际融资额值
				$("#actLsAmt").val(finaAmt);
				//重新计算融资额信息
				 var rows = feeGrid.rows;
					 for (var j = 0; j < rows.length; j++) {
						if(rows[j].calBaseCd==ProjectConstant.CAL_BASE_FINANCING&&rows[j].isFixedAmt!=1){
							if(rows[j].isAllowChg==1){

								feeGrid.updateRow(rows[j],{
				                    feeAmt:0,
				                    feePct:0
				                });

							}else{
								var 	amt  =(rows[j].feePct/100*finaAmt).toFixed(2);
								feeGrid.updateRow(rows[j],{
				                    feeAmt: amt,
				                });
							}
						}

					 }


	}




}
	return Number(feeFct);
}




function  getAmt(feePct,calBaseCd,feeTypCd,isFixedAmt){
	 var feeAmt = 0;
		 //如果存在比例值计算金额值
	if(feePct&&isFixedAmt!=1){
		feePct =parseFloat(feePct).toFixed(feeScale)
		//计算费用值
		if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
			//根据融资额计算
			var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
			var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
			  var rows = feeGrid.rows;
			var firstAmt =0;
				 for (var i = 0; i < rows.length; i++) {
				  			var feeTypCd = rows[i].feeTypCd;
					 if(feeTypCd=="01"){
		        	 		 var detailFct = parseFloat(rows[i].feePct)/100;
				  			var calCd = rows[i].calBaseCd;
				  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
				  			firstAmt  =(detailFct*contAmt).toFixed(2);
				  			}
				  			if(calCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				  				firstAmt  =(detailFct*totalAmt).toFixed(2);
				  			}
			  			}
				 }
				var financ = contAmt-firstAmt;
			//根据设备款计算
			feeAmt =(parseFloat(feePct)/100*financ).toFixed(2);
		}

	if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			//根据合同额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		feeAmt =(parseFloat(feePct)/100*contAmt).toFixed(2);
		}

	//设备款
	if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
		//根据合同额计算
	var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
	feeAmt =(parseFloat(feePct)/100*totalAmt).toFixed(2);
	}

	//如果更改首期款，融资额费用项为不可修改，按比例重新计算计入融资额的费用项，如果融资额费用项可以修改，清空费用项，修改实际融资额值
	if(feeTypCd=='01'){
		//根据融资额计算
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		var totalAmt =(parseFloat($("#totLsItmAmt").val())).toFixed(2);
		var firstAmt = 0;
		 var detailFct = parseFloat(feePct)/100;
			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			firstAmt  =(detailFct*contAmt).toFixed(2);
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				firstAmt  =(detailFct*totalAmt).toFixed(2);
			}
		//融资额
		var finaAmt = 0;
		if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
			finaAmt  =contAmt-firstAmt;
			}
			if(calBaseCd==ProjectConstant.CAL_BASE_TOTAL_PRD_AMT){
				finaAmt  =totalAmt-firstAmt;
			}
			//设置实际融资额值
		//	if(finaAmt>0){
				//
				$("#actLsAmt").val(finaAmt);
				//重新计算融资额信息
				 var rows = feeGrid.rows;
					 for (var j = 0; j < rows.length; j++) {

						if(rows[j].calBaseCd==ProjectConstant.CAL_BASE_FINANCING&&rows[j].isFixedAmt!=1){
							if(rows[j].isAllowChg==1){

								feeGrid.updateRow(rows[j],{
				                    feeAmt: 0,
				                    feePct:0
				                });

							}else{
								var 	amt  =(rows[j].feePct/100*finaAmt).toFixed(2);
								feeGrid.updateRow(rows[j],{
				                    feeAmt: amt,
				                });


							}
						}

					 }

		//	}

	}
	}
	return Number(feeAmt);
}

//查找年利率
function searchAnnIntRatePct(){
	var params = {};
	params.quatId=$("#prpsCfgId").val();
	params.lsPd = $("#lsPd").val();
	params.lsPdUntCd = $("#lsPdUntCd").val();
	var patrn = /^\d+$/;
	if(params.lsPd && (patrn.exec(params.lsPd) == null || patrn.exec(params.lsPd) == '')){
		top.$.ligerDialog.SQalert({SQ_type: "warning",content: "期数只能填正整数！"});
		return false ;
	}
	$.ajax({
		type: 'post',
		dataType:'json',
		data:params,
		url: '<%=path%>/project/prjquatprps/getQuatPrpsCfgAiByQuatId.do',
		success:function(msg){
			 if(msg.success == 1){
				 if(msg.data){
				 annIntRatePct = parseFloat(msg.data.annIntRatePct).toFixed(annIntScale);
				 var parcent =  null;
				 parcent =parseFloat(msg.data.annIntRatePct).toFixed(annIntScale);
				 $("#annIntRatePct").val(parcent);
				 }
			 }else{
				 if(annIntRatePct!=0){
				 $("#annIntRatePct").val(annIntRatePct);
				 }else{

				 }
			 }
		}
	});
	setRentPeriod();
}
	function setRentPeriod(){
		//根据选择的租赁单位计算租赁周期
		var rentPeriod = '';
		var lsPd = $("#lsPd").val();
		var lsPdUntCd = $("#lsPdUntCd").val();
		if(lsPd!=''){
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_MONTH){
				rentPeriod = parseFloat(lsPd)*1;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_YEAR){
				rentPeriod = parseFloat(lsPd)*12;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_DOUBLE_MONTH){
				rentPeriod = parseFloat(lsPd)*2;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_SEASON){
				rentPeriod = parseFloat(lsPd)*3;
			}
			if(lsPdUntCd==ProjectConstant.LS_PD_UNT_HALF_YEAR){
				rentPeriod = parseFloat(lsPd)*6;
			}
		}
		//设置租赁周期
		$("#rentPeriod").text(rentPeriod);
	}
	//修改合同额的时候修改根据合同额计算的比例金额
	function changeBaseContAmt(){
		var contAmt = (parseFloat($("#contAmt").val())).toFixed(2);
		if(contAmt){
            $("#totLsItmAmt").val($("#contAmt").val());
        }
		  var rows = feeGrid.rows;
		  if(!rows||rows.length==0){
			  if(feeGrid.data){
			  rows = feeGrid.data.rows;

		//首期款比例相等，计算融资额，不相等设置融资额大小比例相等的比例值
			var firstAmt =0;
		     for (var j = 0; j < rows.length; j++) {
		    	  var minPct = parseFloat(rows[j].feePctMin)/100;
            	  var maxPct = parseFloat(rows[j].feePctMax)/100;
        		  if(minPct==maxPct){

       			 if(rows[j].feeTypCd=="01"){
        	 		 var detailFct = minPct;
		  			var calCd = rows[j].calBaseCd;
		  			if(calCd==ProjectConstant.CAL_BASE_CONTRACT){
		  			firstAmt  =(detailFct*contAmt).toFixed(2);
		  			}
		  			break;
	  				}

        		  }
		     }
          for (var i = 0; i < rows.length; i++) {
        	  var detailFct = (parseFloat(rows[i].feePct)/100).toFixed(feeScale);
		  			var calBaseCd = rows[i].calBaseCd;
        	  if(detailFct&&detailFct!='NaN'){
		  			var amt =(detailFct*contAmt).toFixed(2);
		  			if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
		  				feeGrid.updateRow(rows[i],{
		                    feeAmt: amt
		                });
					}
        	  }else{
        		  if(rows[i].feePctMin!='NaN'&&rows[i].feePctMax!='NaN'&&rows[i].feePctMin!='undefined'&&rows[i].feePctMax!='undefined'
        			  &&rows[i].feePctMin!=null&&rows[i].feePctMax!=null){
	        		  var minPct = parseFloat(rows[i].feePctMin)/100;
	            	  var maxPct = parseFloat(rows[i].feePctMax)/100;
	            	  var baseCd = rows[i].calBaseCd;
	        		  if(minPct==maxPct){
	        				var amt =(minPct*contAmt).toFixed(2);
	        			  if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
	  		  				feeGrid.updateRow(rows[i],{
	  		                    feeAmt: amt,
	  		                    feePct:(minPct*100).toFixed(feeScale)
	  		                });
	  					}else{
  						     //有首期款，计入方式为融资额，大小比例值相等，计算融资额
	  						if(firstAmt>0&&calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
	  							var finalAmt = contAmt-firstAmt;
	  							$("#actLsAmt").val(finalAmt);
	  							var amt =(minPct*finalAmt).toFixed(2);
	  							feeGrid.updateRow(rows[i],{
		  		                    feeAmt: amt,
		  		                    feePct:(minPct*100).toFixed(feeScale)
		  		                });

	  						}else{
	  						  if(calBaseCd==ProjectConstant.CAL_BASE_CONTRACT){
	  							feeGrid.updateRow(rows[i],{
		  		                    feePct:(minPct*100).toFixed(feeScale),
		  		                  feeAmt: amt,
		  		                });
	  						  }

	  						  if(calBaseCd==ProjectConstant.CAL_BASE_FINANCING){
		  							feeGrid.updateRow(rows[i],{
			  		                    feePct:(minPct*100).toFixed(feeScale),
			  		                  	feeAmt: 0,
			  		                });
	  						  }
	  						}

	  					}
	        		  }else{
	        			  // 比例不相同不计算，金额默认为0
	        			  feeGrid.updateRow(rows[i],{
	  		                    feeAmt: 0
	  		                });
	        		  }
        		  }else{
        			  var isFixedAmt = rows[i].isFixedAmt;
        			  var fixedAmt = rows[i].fixedAmt;
        			  if(typeof fixedAmt=='number'&&isFixedAmt==1){
        				  feeGrid.updateRow(rows[i],{
  		                    feeAmt: fixedAmt
  		                });

        			  }

        		  }

        	  }
          };

			  }
		  }


	}
	function initCalculatePage(flag){
			 var prpsId=$("#prpsId").val();
		 calculateGrid = $("#ligergrid_calculate").ligerGrid({
			 url:'<%=path%>/project/calquatprps/getPrjQuatPayById.do?id='+prpsId,
	        method: 'get',
		     columns: [
		         { display: '支付时间', name: 'payDt', render:renderDate, minWidth: 60 },
		         { display: '期次', name: 'payPd',minWidth: 140},
		         { display: '租金', name: 'rntAmt', minWidth: 140, type:'currency',render:renderAmt,editor: {type: 'number',
		        	 precision:2,
	    				toFix:true,
	    				onToFix:function(){
    					 top.$.ligerDialog.SQalert({SQ_type: "warning",content: "小数点后面最多2小数！"});
    				}
		         }, enabledSort:true},
		         { display: '本金', name: 'prinAmt', minWidth: 60, type:'currency',
		        	 render:renderAmt},
		         { display: '利息', name: 'intAmt', minWidth: 140, type:'currency',
		        		 render:renderAmt},
		         { display: '剩余本金', name: 'remPrinAmt', minWidth: 140, type:'currency',
		        			 render:renderAmt},
		     ],
		     onBeforeEdit: function (e) {
	                e.lastValue = e.value;
	                if(!e.record.isModify){
	                	e.record.isModify= CommonConstant.C_YN_N;
	                }
	            },
		        onAfterEdit: function (e) {
		            var calBaseCd = e.record.calBaseCd;
		          	if(e.column.name =="rntAmt"){
		          		var value = e.value;
		          	var lastValue = e.lastValue;
		               	 if(value!=lastValue&&lastValue){
		               		 isModify = true;
		               		e.record.isModify= CommonConstant.C_YN_Y;
		               	 }
		          	}
		          },
		     usePager: false,
		     pageSize:10,
		     root:'rows',
		     record:'total',
		     hideLoadButton : true,
		     width: '100%',
		     height:300,
		     heightDiff:-2,
		     //isScroll: false,
		     checkbox:true,
		     enabledEdit: flag,
		     rownumbers:true
		});
	}
	//格式化为人民币格式
	function renderAmt(rowdata, rowindex, value) {
		value = Number(value);
		if(typeof value =='number'){

        var  h="￥" + FormatMoney((parseFloat(value)).toFixed(2));
        return h;
		}
    }
	//格式化时间
	function renderDate(rowdata, index, value){
		var dateStr = "";
		if(null != value){
			var date = new Date(value);
			dateStr = DateUtils.formatDate(date, DateUtils.YYYY_MM_DD);
		}
		return dateStr;
	}

	function speLsPdChange() {
		var payWayCd = $("#payWayCd").val();
		if(payWayCd==ProjectConstant.CODE_MULTI_STEP_INTER_19){
			$("#speLsPdDiv").show();
		}else{
			$("#speLsPdDiv").hide();
		}
	}

</script>



</body>
</html>
